package bstsetcode;



/**
 * 定义一个泛型类
 * @author noob
 * @version 1.0
 * @date 2021/3/13 9:45
 */
public class LinearSearchT<E> {


    private LinearSearchT() {
    }

    public static <E> int search(E[] data, E target){

        for (int i = 0; i < data.length; i++) {
            if(data[i].equals(target)){ //注意
                return i;
            }
        }
        return -1;
    }

    /**
     * 泛型只能接收包装类
     * @param args args
     */
    public static void main(String[] args) {
        Integer[] data = {39, 71, 91, 90 ,51, 83, 70, 80, 26, 8};
        int res = LinearSearchT.search(data, 91);
        System.out.println(res);

        int res2 = LinearSearchT.search(data, 520);
        System.out.println(res2);

        Student[] students = {
                new Student("faker"),
                new Student("bang"),
                new Student("bengi"),
        };
        Student faker = new Student("faker");
        int i = LinearSearchT.search(students, faker);
        System.out.println(i);
    }




}
